﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Minecraft.Data.NBT;

namespace Minecraft.Data {
    public class InventoryItem: ITagConverter {

        public ItemType ID;
        public short Damage;
        public byte Count;
        public byte Slot;

        public InventoryItem() { }
        public InventoryItem(Tag data) {

            foreach (var child in data.Children) {
                switch (child.Name) {

                    case "id":
                        this.ID = (ItemType)child.Payload;
                        break;

                    case "Damage":
                        this.Damage = (short)child.Payload;
                        break;

                    case "Count":
                        this.Count = (byte)child.Payload;
                        break;

                    case "Slot":
                        this.Slot = (byte)child.Payload;
                        break;
                    
                    default:
                        break;
                }
            }
        }

        public Tag ToTag() {
            Tag root = new Tag() { Type = TagType.Compound, Name = "" };
            root.Children.Add(new Tag() { Type = TagType.Short, Name = "id", Payload = Convert.ToInt16(ID) });
            root.Children.Add(new Tag() { Type = TagType.Short, Name = "Damage", Payload = Damage });
            root.Children.Add(new Tag() { Type = TagType.Byte, Name = "Count", Payload = Count });
            root.Children.Add(new Tag() { Type = TagType.Byte, Name = "Slot", Payload = Slot });
            return root;
        }
    }
}
